package com.usermanage.controller;

import com.usermanage.Service.GroupPermissionService;
import com.usermanage.beanParam.GroupPermissionBean;
import com.usermanage.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 *
 */
@Api(description = "用户角色组管理")
@RestController
@RequestMapping("/groupPermission")
public class GroupPermissionController {

    @Resource
    private GroupPermissionService groupPermissionService;


















    /**
     * @return
     */
    @ApiOperation(value = "根据组id得到角色权限列表" ,  notes="根据组id得到角色权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组id", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value="/getGroupMemberListByGroupId",method= RequestMethod.GET)
    public JsonData getRoleListByGroupId(@RequestParam("groupId") String groupId){
        //根据角色id得到权限列表
//        List list = groupPermissionService.getRoleListByGroupId(groupId);
        return JsonData.success();
    }



    /**
     *
     * @param groupPermissionBean   权限组对象
     * @param bindingResult   valid验证接收验证结果
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "添加权限组信息" ,  notes="添加权限组信息")
    @RequestMapping(value="/addGroupPermission",method= RequestMethod.POST)
    public JsonData creatGroupPermission(@Valid @RequestBody GroupPermissionBean groupPermissionBean, BindingResult bindingResult)throws Exception{
        //验证提交参数
        if(bindingResult.hasErrors()){//valid验证是否通过
            return JsonData.fail(bindingResult.getFieldError().getDefaultMessage()); //valid验证不通过返回错误信息
        }
        //创建权限组
//        int addResult = groupPermissionService.creatGroupPermission(groupPermissionBean);
//        if (addResult>0){
//            return JsonData.success();
//        }else {
//            return JsonData.fail("添加组织错误，系统异常！");
//        }
        return JsonData.success();
    }



    @ApiOperation(value = "组织作废时删除组织下所有权限" ,  notes="组织作废时删除组织下所有权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组id", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value="/delRoleByGroupId",method= RequestMethod.GET)
    public JsonData delRoleByGroupId(@RequestParam("groupId") String groupId){
        //根据角色id得到权限列表
//        List list = groupPermissionService.getRoleListByGroupId(groupId);
        return JsonData.success();
    }
}
